# -*- coding: utf-8 -*-
"""
Module Description:
Date: 2017/6/2
Author:
"""


class RoleDrillStatusMixin(object):
    __slots__ = ()

    drill_point = NotImplemented
    role_guid = NotImplemented

    def drill_point_to_activity(self, val):
        old_value = self.drill_point
        import pyshare.bll.events as events
        import zope.component
        from pyshare.const.enums.activity import ActivityType
        add_value = val - old_value
        time_event = events.ActivityProgressChanged(
            role_id=self.role_guid,
            a_type=ActivityType.DrillField,
            add_value=add_value
        )
        zope.component.handle(time_event)

        # update: 移到外面触发，避免联盟活动加锁无效
        # # 联盟校场积分活动
        # record = AllianceMemberRepository.get_by_rid(self.role_guid)
        # if record and record.alliance_id:
        #     alliance_event = events.ActivityProgressChanged(
        #         alliance_id=record.alliance_id,
        #         a_type=ActivityType.AllianceDrillField,
        #         add_value=add_value,
        #         role_id=self.role_guid
        #     )
        #     zope.component.handle(alliance_event)